<template>
  <div class="text-right">
    <slot name="before"></slot>
    <TradeDateModel type="info" icon="el-icon-search" size="mini"  class="dis-lb"  @confirmTradeDate="confirmTradeDate" :trade-date-type="tradeDateType">同步数据</TradeDateModel>
    <el-button type="info" icon="el-icon-search" size="mini"  class="dis-lb"  @click="search" v-if="showSearchButton">搜索</el-button>
    <slot name="after"></slot>
  </div>
</template>
<script >
  import http from "network/http";

  export default {
    props:{
      showSearchButton: {
        type: Boolean ,
        default: true
      },
      tradeDateType: {
        type: String ,
        default: "date"
      },
      syncDataUrl: {
        type: String ,
        required: true
      },
    },
    data(){
      return{
        formData:{}
      }
    },
    methods:{
      confirmTradeDate(tradeDate){
        if(!tradeDate){
          this.$message.error('请选择时间');
          return
        }
        if(this.tradeDateType === "date"){
          const loading = this.$loading({
            lock: true,
            text: 'Loading',
            spinner: 'el-icon-loading',
            background: 'rgba(0, 0, 0, 0.7)'
          });
          http.post(`${this.syncDataUrl}/${tradeDate}`).then(res=>{
            console.log(res)
          }).finally(()=>{
            loading.close();
          })
        }

      },
      editSuccess(res){
        this.$emit("addSuccess",res)
      },
      search(){
        this.$emit("search")
      }
    }
  }
</script>
<style scoped>

</style>
